package org.example.modules.user.service.Impl;

import lombok.extern.slf4j.Slf4j;
import org.example.modules.user.entry.Chat;
import org.example.modules.user.mapper.ChatMapper;
import org.example.modules.user.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * @Description ChatServiceImpl
 * @Author xiaotian
 * @Date 2025-04-20
 */
@Slf4j
@Service
public class ChatServiceImpl implements ChatService {

    @Autowired
    private ChatMapper chatMapper;

    @Override
    public Chat sendMessage(Chat chat) {
        chat.setCreatedAt(LocalDateTime.now().toString());
        log.info("发送消息：{}", chat);
        chatMapper.insert(chat); // 插入新消息
        return chat;
    }

    @Override
    public List<Chat> getMessages(String senderId, String receiverId,Integer jobId) {
        return chatMapper.findBySenderIdAndReceiverId(senderId, receiverId,jobId);
    }

    @Override
    public List<Chat> getMessagesByOrderId(Integer orderId) {

        return chatMapper.getMessagesByOrderId(orderId);
    }
}